package JAVA300.第十一章多线程;

/**
 * 死亡状态
 * 终止线程学习
 */

public class thread_11_threadState_terminate implements Runnable{
    //1.add结束标志
    private boolean flag = true;
    private String name;

    public thread_11_threadState_terminate(String name) {
        this.name = name;
    }

    @Override
    public void run() {
        int i=0;
        //2.关联标志
        while (flag){
            System.out.println(name+"-->"+(i++));
        }

    }
    //3.对外提供改变方法
    public void terminate(){
        this.flag= false;
    }

    public static void main(String[] args) {
        thread_11_threadState_terminate tt = new thread_11_threadState_terminate("TestThread");
        new Thread(tt).start();

        for (int i= 0;i<99;i++){
            if (i == 88){
                tt.terminate();
                System.out.println("testOver");
            }

            System.out.println("mainThread"+i);
        }

    }
}
